/**
 * $File: TT_Graphics_DrawObj.cpp
 * $Synopsis: Graphics Stuff Implementation
 * $Author: Ted Yin (ymfoi)
 * $Version: alpha 1.0
 * $Date: Sat Nov 27 22:45:56 2010 CST
 */

#include "TT_Graphics_DrawObj.h"

void TT_Graphics::Draw_Arena(int Arena_Row,int Arena_Col) {

	glLineWidth(1.0);
	glColor3f(0.1,0.1,0.1);
	glBegin(GL_LINES);

	for (int i = 0; i < Arena_Row * FACTOR; i++)
		if (!(i % 20)) {glVertex3d(i,0,0); glVertex3d(i,Arena_Col * FACTOR,0);}

	for (int i = 0; i < Arena_Col * FACTOR; i++)
		if (!(i % 20)) {glVertex3d(0,i,0); glVertex3d(Arena_Row * FACTOR,i,0);}

	glEnd();

}

void TT_Graphics::Draw_Player_Quad(const TT_Core::PlayerNode *ptr) {

	int lx = ptr -> Route.head -> x,ly = ptr -> Route.head -> y;
	UCHAR Dir = -1,PDir = -1;
	glColor4f(ptr -> Red / 255.0,ptr -> Green / 255.0,ptr -> Blue / 255.0,ptr -> Alpha);
	glLineWidth(5.0);
	glBegin(GL_QUAD_STRIP);

	for (TT_Core::PosNode *now = ptr -> Route.head -> next; now; now = now -> next)
	{
		int nx = now -> x;
		int ny = now -> y;
		if (lx == nx) Dir = 0; else Dir = 1;
		if (PDir != Dir) 
		{
			glVertex3f(lx * FACTOR,ly * FACTOR,QUAD_HEIGHT);
			glVertex3f(lx * FACTOR,ly * FACTOR,1);

			PDir = Dir;
		}
		lx = nx,ly = ny;
	}	
	glVertex3f(lx * FACTOR,ly * FACTOR,QUAD_HEIGHT);
	glVertex3f(lx * FACTOR,ly * FACTOR,0);

	glEnd();
}

void TT_Graphics::Draw_Player_UpOutline(const TT_Core::PlayerNode *ptr) {

	int lx = ptr -> Route.head -> x,ly = ptr -> Route.head -> y;
	UCHAR Dir = 0,PDir = -1;
	glColor4f(ptr -> Red / 255.0 - 0.2,ptr -> Green / 255.0 - 0.2,ptr -> Blue / 255.0 - 0.2,ptr -> Alpha);
	glLineWidth(5.0);
	glBegin(GL_LINE_STRIP);

	for (TT_Core::PosNode *now = ptr -> Route.head -> next; now; now = now -> next)
	{
		int nx = now -> x;
		int ny = now -> y;
		if (lx == nx) Dir = 0; else Dir = 1;
		if (PDir != Dir) 
		{
			glVertex3f(lx * FACTOR,ly * FACTOR,QUAD_HEIGHT);

			PDir = Dir;
		}
		lx = nx,ly = ny;
	}	
	glVertex3f(lx * FACTOR,ly * FACTOR,QUAD_HEIGHT);
	glEnd();

}

void TT_Graphics::Draw_Player_DownOutline(const TT_Core::PlayerNode *ptr) {

	int lx = ptr -> Route.head -> x,ly = ptr -> Route.head -> y;
	UCHAR Dir = 0,PDir = -1;
	glColor4f(ptr -> Red / 255.0 - 0.2,ptr -> Green / 255.0 - 0.2,ptr -> Blue / 255.0 - 0.2,ptr -> Alpha);
	glLineWidth(5.0);
	glBegin(GL_LINE_STRIP);

	for (TT_Core::PosNode *now = ptr -> Route.head -> next; now; now = now -> next)
	{
		int nx = now -> x;
		int ny = now -> y;
		if (lx == nx) Dir = 0; else Dir = 1;
		if (PDir != Dir) 
		{
			glVertex3f(lx * FACTOR,ly * FACTOR,1);

			PDir = Dir;
		}
		lx = nx,ly = ny;
	}	
	glVertex3f(lx * FACTOR,ly * FACTOR,1);
	glEnd();
}

void TT_Graphics::Draw_Player_Vertical(const TT_Core::PlayerNode *ptr) {

	int lx = ptr -> Route.head -> x,ly = ptr -> Route.head -> y;
	UCHAR Dir = ptr -> Now_Dir,PDir = -1;
	glColor4f(ptr -> Red / 255.0 - 0.2,ptr -> Green / 255.0 - 0.2,ptr -> Blue / 255.0 - 0.2,ptr -> Alpha);
	glLineWidth(5.0);
	glBegin(GL_LINES);

	for (TT_Core::PosNode *now = ptr -> Route.head; now; now = now -> next)
	{
		int nx = now -> x;
		int ny = now -> y;
		if (lx == nx) Dir = 0; else Dir = 1;
		if (PDir != Dir) 
		{
			glVertex3f(lx * FACTOR,ly * FACTOR,QUAD_HEIGHT);
			glVertex3f(lx * FACTOR,ly * FACTOR,1);

			PDir = Dir;
		}
		lx = nx,ly = ny;
	}
	glVertex3f(lx * FACTOR,ly * FACTOR,QUAD_HEIGHT);
	glVertex3f(lx * FACTOR,ly * FACTOR,1);

	glEnd();
}

